<?php

namespace plugin\admin\app\model;

use Illuminate\Database\Eloquent\Relations\HasOne;
use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property integer $device_id 设备id
 * @property string $child_sn 子设备编号
 * @property string $extend 扩展字段
 * @property integer $storage_id 存储设备uid
 * @property string $storage_action 存储动作
 * @property string $collect_action 采集动作
 * @property integer $child_device_id 子设备id
 * @property integer $point_group_id 点位组
 * @property integer $collect_task_id 采集任务id
 * @property string $create_time 创建时间
 */
class IotCollectDetail extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'iot_collect_detail';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * 获取任务关联的设备信息
     * @return HasOne
     */
    public function get_device(): HasOne
    {
        return $this->hasOne(IotDevice::class,'id','device_id')->select(['id','name','ip','port','device_sn','is_lecp_server','lecp_server_name']);
    }

    /**
     * 获取任务关联的子设备设备信息
     * @return HasOne
     */
    public function get_child_device(): HasOne
    {
        return $this->hasOne(IotDeviceChild::class,'id','child_device_id')->select(['id','name','device_id','data_format']);
    }

    /**
     * 获取任务关联的子设备设备信息
     * @return HasOne
     */
    public function get_point_group(): HasOne
    {
        return $this->hasOne(IotPointGroup::class,'id','point_group_id')->select(['id','name','device_type_id','model_id','signal_json']);
    }
}
